package com.time.admin.application.converter;

import com.time.admin.application.dto.TagDTO;
import com.time.admin.common.entity.PageResult;
import com.time.admin.domain.entity.TagBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 标签DTO转换类
 *
 * @author: HuangQi
 * @date: Created in 11:27 2025/10/14
 * @description: 标签DTO转换类
 */
@Mapper
public interface TagDTOConverter {
    TagDTOConverter INSTANCE = Mappers.getMapper(TagDTOConverter.class);

    TagBO convertDTOToBO(TagDTO tagDTO);

    List<TagDTO> convertBOListToDTO(List<TagBO> tagBOList);

    default PageResult<TagDTO> convertBOPageToDTOPage(PageResult<TagBO> boPage){
        PageResult<TagDTO> dtoPage = new PageResult<>();
        if (boPage == null) {
            return dtoPage;
        }
        dtoPage.setPageNo(boPage.getPageNo());
        dtoPage.setPageSize(boPage.getPageSize());
        dtoPage.setTotal(boPage.getTotal());
        dtoPage.setTotalPage(boPage.getTotalPage());
        dtoPage.setStart(boPage.getStart());
        dtoPage.setEnd(boPage.getEnd());
        if (boPage.getResult() != null && !boPage.getResult().isEmpty()) {
            List<TagDTO> dtoList = convertBOListToDTO(boPage.getResult());
            dtoPage.setResult(dtoList);
        }
        return dtoPage;
    }
}
